
/*
	(c) Galustyan Sergey 2009
*/

#pragma once
#include "Lib.h"
#include "OclTask.hpp"

namespace TestTask
{
	class RayComputer:public RenderObject,public OclTaskSolver{
		public:
			RayComputer( PDevice device, PSuperSphere s1, PSuperSphere s2, PTexture land );
	
		private:
			virtual void  computeOcl( RenderPackage& rp, int sphereNumber ); // prepare divice, call other functions, store statistic
						
			typedef boost::tuple<bool,float> Stat;		  // Stat - <bool - center visibility, float - visibility factor>

			Stat  readResultTexture( PDevice device );    // get occlusion data from render target
			void  prepareAnglesTexture( PDevice device ); // one time, preapre angles params texture, which used to compute rays
			void  prepareDevice( PDevice device );		  // set render target, safe backbuffer
			void  freeDevice( PDevice device );			  // restore backbuffer
			void  Render( RenderPackage& rp );			  // render screenQuad to render Target, compute occlusion in pixel shader
		
			PVertexBuffer screenQuad;					  // used to render full buffer quad - so provide data to pixel shader
		
			PTexture	  rays, land, renderTexture, renderResult; // rays = angles, that allow to compute rays, land = hiehgtmap,
																   // renderTexture = renderTarget and renderResult is needed to 
																   // copy renderTexture back to CPU memoty

			PSurface	  renderSurface, backBuffer, renderResultSurface; // surfaces use to access textures
		
			SetEffectParameter setLookDirection,setLookUp,setLookRight,
							   setSpherePosition,setSphereRadius,
							   setRayOrig,
							   setRaysTexture,setLandTexture,setLandMetric,setLandbase;
	};

	declaresmart(RayComputer)
}

